package com.wang.store.interceptor;

import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class LoginInterceptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request,
                             HttpServletResponse response,
                             Object handler) throws Exception {
        Object uid = request.getSession().getAttribute("uid");
        if (uid==null) {
            //用户没有登录系统
            response.sendRedirect("/web/login.html");
            return false;
        }
        //正常放行
        return  true;
    }
}
